package com.liarjo.my_website_api.security;

import com.liarjo.my_website_api.security.pojo.SecurityUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public class SecurityUtil {
    public SecurityUser getSecurityUser() {
        return (SecurityUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    public Collection<? extends GrantedAuthority> getAuthorities() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication.getAuthorities();
    }
}
